package com.lzp.config;

import com.lzp.batch.MyExcelReader;
import com.lzp.batch.MyExcelWriter;
import com.lzp.entity.WechatBill;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.core.step.tasklet.TaskletStep;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import javax.annotation.Resource;
import java.io.File;

/**
 * @author : lzp
 * @date : 2021/9/23 19:38
 * @describe : TODO
 * @vision 1.0
 */
@Configuration
@EnableBatchProcessing
public class MyJobConfig {

    @Resource
    StepBuilderFactory stepBuilderFactory;
    @Resource
    MyExcelReader myExcelReader;
    @Resource
    MyExcelWriter myExcelWriter;
    @Autowired
    private JobBuilderFactory jobs;

    @Bean
    public Job job() {
        return jobs.get("myJob").start(step()).build();
    }
    @Bean
    public Step step(){
        System.out.println("加载bean");
        return stepBuilderFactory.get("step")
                .chunk(10)
                .reader(myExcelReader)
                .writer(myExcelWriter)
                .build();
    }
}
